package com.cl.blog.mq;

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

import static com.cl.blog.config.RabbitMqConfig.*;

/**
 * @Author 付
 * @Date 2024-04-01 11:31
 * @Version 1.0
 * @description 延时队列生产者
 * @since 1.0
 */
//@Component
public class DelayMessageSender {

	@Autowired
	private RabbitTemplate rabbitTemplate;

//	public void sendMsg(String msg, DelayTypeEnum type) {
//		switch (type) {
//			case DELAY_10s:
//				rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUEA_ROUTING_KEY, msg);
//				break;
//			case DELAY_60s:
//				rabbitTemplate.convertAndSend(DELAY_EXCHANGE_NAME, DELAY_QUEUEB_ROUTING_KEY, msg);
//				break;
//		}
//	}

	public void sendDelayMsg(String msg, Integer delayTime) {
		System.out.println(msg + "---" + delayTime);
		rabbitTemplate.convertAndSend(DELAYED_EXCHANGE_NAME, DELAYED_ROUTING_KEY, msg, a -> {
			a.getMessageProperties().setDelay(delayTime);
			return a;
		});
	}


}
